home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / updates / update32.zoo / lib / ffs.c < prev   
Encoding:
C/C++ Source or Header  |  1993-07-14  |  597 b   |  48 lines

  1. /*
  2.   ffs.c - find first set bit
  3.   Carmine T. Guida
  4.   7 - 7 - 93 Public Domain
  5. */
  6.  
  7. #include <support.h>
  8.  
  9. int
  10. ffs(bits)
  11.   int bits;
  12. {
  13.   register int i;
  14.  
  15.   if (!bits)
  16.     return 0;
  17.  
  18.   i = 1;
  19.  
  20. #ifndef __MSHORT__
  21.   if (!(bits & 0x0000FFFF))    /* Check word */
  22.   {
  23.     bits >>= 16;
  24.     i += 16;
  25.   }
  26. #endif
  27.  
  28.   if (!(bits & 0x00FF))        /* Check byte */
  29.   {
  30.     bits >>= 8;
  31.     i += 8;
  32.   }
  33.   if (!(bits & 0x0F))        /* Check nybble */
  34.   {
  35.     bits >>= 4;
  36.     i += 4;
  37.   }
  38.   if (!(bits & 0x3))        /* Check 2 bits */
  39.   {
  40.     bits >>= 2;
  41.     i += 2;
  42.   }
  43.   if (!(bits & 0x1))        /* Check bit */
  44.     i += 1;
  45.  
  46.   return i;
  47. }
  48.